Contents Previous Next

Java 3D API Specification


A P P E N D I X E

Equations




THIS appendix contains the Java 3D equations for fog, lighting, sound, and texture mapping. Many of the equations use the following symbols:

· Multiplication
Function operator for Sound Equations,
Dot product for all other Equations

E.1 Fog Equations

To be supplied.

E.2 Lighting Equations

The ideal lighting equation is as follows:


Note: If (Li N) 0, then diffi and speci are set to 0.


Note: For directional lights, atteni is set to 1.


Note: If the vertex is outside the spotlight cone, as defined by the cutoff angle, spoti is set to 0. For directional and point lights, spoti is set to 1.

This is a subset of OpenGL in that the Java 3D ambient and directional lights are not attenuated and only ambient lights contribute to ambient lighting.

The parameters used in the lighting equation are as follows:

E = Eye vector
Ma = Material ambient color
Md = Material diffuse color
Me = Material emissive color
Ms = Material specular color
N = Vertex normal
shin = Material shininess

The per-light values are as follows:

di = Distance from vertex to light
Di = Spotlight direction
expi = Spotlight exponent
Kci = Constant attenuation
Kli = Linear attenuation
Kqi = Quadratic attenuation
Li = Direction from vertex to light
Lci = Light color
Si = Specular half-vector = || (Li + E) ||

Fallbacks and Approximations

E.3 Sound Equations

There are different sets of sound equations, depending on the use of headphones or speakers.

E.3.1 Headphone Playback Equations

For each sound source, Java 3D calculates a separate left and right output signal. Each left and right sound image is made up of the an interaural intensity and an interaural delay. The calculation results are a set of direct and indirect (delayed) sound signals mixed together when sent to the audio playback system left and right transducers.

E.3.1.1 Interaural Time Difference (Delay)

For each point and cone sound source node, the left and right output signals are delayed based on the location of the sound and the orientation of the head. This time difference between these two signals is called the interaural time difference (ITD). This time delay of a particular sound reaching the far ear is affected by the shadow of the listener's head. Java 3D uses an approximation of the ITD using a spherical head model. The interaural path difference is calculated based on the following cases:

The time from the sound source to the closest ear is Ec/S, and the time from the sound source to the farthest ear is Ef/S, where S is the region's speed of sound.

If sound is closest to left ear then:

If sound is closest to right ear then

The parameters used in the ITD equations are as follows:

= Angle between Vh and Va in radians
De = Distance between ears (interaural distance)
Dh = Distance from interaural center to sound source
Ec = Distance from sound source to ear closest to sound
Ef = Distance from sound source to ear farthest from sound
P = Difference between Paths to right and left ears from source
Va = Vector from center ear forward parallel to Z axis of head coordinates
Vc = Vector from sound source to ear closest to sound
Vf = Vector from sound source to ear farthest from sound
Vh = Vector from center ear to sound source

E.3.1.2 Interaural Intensity (Gain) Difference

For each active and playing Point and ConeSound source, s, separate calculations for the left and right signal (based on which ear is closest and which is farthest to the source) are combined with non-spatialized BackgroundSound to create a stereo sound image.


Note: For BackgroundSound sources ITD() is an identity function so there is no delay applied to the sample for these sources.


Note: For BackgroundSound sources Gd() = Ga() = 1.0. For PointSound sources Ga() = 1.0.


Note: For BackgroundSound sources Fd() and Fa() are identity functions. For PointSound sources Fa() is an identity function.

If the Sound source is on the right side of the head, Ec is used for left G and F calculations and Ef is used for right. Conversely, if the Sound source is on the left side of the head, Ef is used for left calculations and Ec is used for right.

E.3.1.3 Attenuation

For the vector from the sound source position through the listener's position, intersection points on the spheres, defined by the distance attenuation array, define both the index k within the distanceAttenuation arrays from which distance gain scale factors are acquired, and the distances, d1 = d[k] and d2 = d[k+1] from the sound position to these intersection points.

For the vector from the sound source position through the listener's position, intersection points on the two ellipses closest to the listener (points A and B) define both the index k within the front and back distanceAttenuation arrays from which distance gain scale factors are acquired, and the distances, d1 and d2, from the sound position to these intesection points.

The equation for the distance gain is:

Angular Attenuation for both the spherical and elliptical cone sounds is identical. The angular distances in the attenuation array closest to is found and define the index k into the angular attenuation array elements. The equation for the angular gain is:

The parameters used in the IID equations are as follows:

A, B = DistanceAttenuation pairs containing linear distance and gain scale factor
C,D = AngularAttenuation pairs containing angular distance and gain scale factor
= Angle between Vh and Va in radians
d = Distance from sound source to left or right ear (either Ec or Ef)
Ec = Distance from sound source to ear closest to sound from the ITD equation
Ef = Distance from sound source to ear farthest from sound source from the ITD equation
Fa = Angular filter from ConeSound definition
Fd = Distance Filter from aural attribute
Ga = Angular Gain attenuation scale factor
Gd = Distance Gain attenuation scale factor
Gi = Initial Gain scale factor
I = Stereo sound image
L = Listener distance from sound source
maxNumS = Maximum number of sound sources for the audio device application is using for playback
numS = Number of sound sources
sample = Sound digital sample with a specific sample rate, bit precision and an optional encoding and/or compression format.
Vh = Vector from center ear to sound source

E.3.1.4 Doppler Effect Equations

The frequency of sound waves emanating from the source are lowered based on the speed of the source in relation to the listener, and the sound wave length, as follows:

The parameters used in the Doppler effect equations are as follows:

Dh = Distance from sound source to center ear
Ds = Doppler scale factor (AuralAttribute field)
Dv = Doppler velocity (between the listener and sound source)
f = Frequency
S = Sound source frequency
t = Time
W = Wavelength of sound source based on frequency and distance

E.3.1.5 Reverberation Equations

The overall reverberant sounds, used to give the impression of the aural space the active/enabled source sources are playing in, is added to the stereo sound image output from equation (Eq9).

Reverberation for each sound is approximated in the following:

Note that the reverberation calculation outputs the same image to both left and right output signals (thus there is a single mono calculation for each sound reverberated). Correct first-order (early) reflections, based on the location of the sound source, the listener, and the active AuralAttribute bounds, are not required for this version of Java 3D. Approximations based on the reverberation delay time, either suppled by the application or calculated as the average delay time within the selected AuralAttribute application region, will be used

The feedback loop is repeated until AuralAttribute reverberation feedback loop count is reached or Gri 0.000976 (effective zero amplitude, -60dB, using the measure of -6dB drop for every doubling of distance).

Fallbacks and Approximations

The parameters used in the Reverberation equations are as follows:

D = Delay function.
Dr = Reverberation first-order delay.
fLoop = Reverberation feedback loop count.
Gr = Reverberation coefficient acting as a gain scale-factor.
I = Stereo image of unreflected sound sources.
R = Reverberation for each sound sources.
Sample = Sound digital sample with a specific sample rate, bit precision, and an optional encoding and/or compression format.
t = Time.
Tr = Reverberation delay time (approximating first-order delay in the AuralAttribute region).

E.3.1.6 Low-pass Filtering

An N-pole low-pass filter may be used to perform the simple angular and distance filtering defined in this version of Java 3D. These simple low-pass filters are meant only as an approximation for full, FIR filters (to be added in some future version of Java 3D).

Fallbacks and Approximations

E.3.2 Speaker Playback Equations

Different speaker playback equations are used, depending on whether the system uses monaural or stereo speakers.

E.3.2.1 Monaural Speaker Output

The equations for headphone playback need only be modified to output a single signal, rather than two signals for left and right transducers. Although there is only one speaker, distance and filter attenuation, Doppler effect, elevation and front and back cues can be distinguished by the listener and should be included in the sound image generated.

E.3.2.2 Stereo Speaker Output

In a two speaker playback system, the signal from one speaker is actually heard by both ears and this affects the spectral balance and interaural intensity and time differences heard by each of the listener's ears. Cross-talk cancellation must be performed on the right and left signal to compensate for the delayed attenuated signal heard by the ear opposite the speaker. Thus a delayed attenuated signal for each of the stereo signals must be added to the output from the equations for headphone playback.

The equations for stereo speaker playback assume that the two speakers are placed symmetrically about the listener (at the same off-axis angle from the viewing axis at an equal distance from the center of the listener's head).

The parameters used in the cross-talk equations, expanding on the terms used for the equations for headphone playback, are as follows:

= Angle between vectors from speaker to near and far ears
D = Delay function of signal variant over time
G = Gain attenuation scale factors function taking initial, distance and angular gain scale factors into account
I = Sound image for left and right stereo signals calculated as for headphone output
P = Distance difference between near ear and far ear as defined for ITD, the speaker substituted for the sound source in equation
t = Time

E.4 Texture Mapping Equations

To be supplied.



Contents Previous Next

Java 3D API Specification


Copyright © 1997, Sun Microsystems, Inc. All rights reserved.